$(function(){
    // 手机号
    // $("#srsjh>input").focus(function(){
    //     console.log("点击sj输入框");
    //     $("#sjts").html("请输入您的手机号码")
    // })
    $("#srsjh>input").blur(function(){
        if($("#srsjh>input").val()==""){
            $("#sjts").html("请输入手机号码").css("color","red");
        }else{
            var off = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/.test($("#srsjh>input").val());
            if(off){
                $("#sjts").html("手机号正确").css("color","red");
            }else{
                $("#sjts").html("手机号错误").css("color","red");
            }
        }
    })
    // 设置密码
    // $("#mmk").focus(function(){
    //     console.log("点击mm输入框");
    //     $("#sjts").html("请输入您的密码")
    // })
    $("#mmk").blur(function(){
        if($("#mmk").val()==""){
            $("#mmts").html("请输入密码").css("color","red");
        }else{
            var off =/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/.test($("#mmk").val());
            if(off){
                $("#mmts").html("密码正确").css("color","red");
            }else{
                $("#mmts").html("密码错误").css("color","red");
            }
        }
    })
    // 激活码
    $("#jhm>button").click(function(){
        var a=Math.floor(Math.random()*10);
        var b=Math.floor(Math.random()*10);
        var c=Math.floor(Math.random()*10);
        var d=Math.floor(Math.random()*10);
        x=a*1000+b*100+c*10+d;
        $("#jhmts").html(x);
        // console.log(x);
    })
    $("#jhm>input").blur(function(){
        if($("#jhm>input").val()==""){
            $("#jhmts").html("请输入激活码").css("color","red");
        }else{
            var off=$("#jhm>input").val();
            // console.log(off);
            // var off =/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/.test($("#jhm>input").val());
            if(off==x){
                $("#jhmts").html("激活码正确").css("color","red");
            }else{
                $("#jhmts").html("激活码错误").css("color","red");
            }
        }
    })
    // 判断三个条件
    $("#lijizhuce").click(function(){
        if($("#sjts").html()=="手机号正确" &&$("#mmts").html()=="密码正确" && $("#jhmts").html()=="激活码正确"){
            console.log("成功");
            // var a=$("#srsjh>input").val();
            // var b=$("#mmk").val();
            // var c=$("#jhm>input").val();
            // 创建cookie
            // document.cookie=`username=${$("#srsjh>input").val()};password=${$("#mmk").val()};expires=Thu, 18 Dec 2022 12:00:00 GMT`;
            // document.cookie=`username=${$("#srsjh>input").val()};password=${$("#mmk").val()}`;
            // console.log(document.cookie);

            // 封装的，创建cookie
            var username=$("#srsjh>input").val();
            var password=$("#mmk").val();
            function setCookie(cname,cvalue,exdays){
                var d = new Date();
                d.setTime(d.getTime()+(exdays*24*60*60*1000));
                var expires = "expires="+d.toGMTString();
                document.cookie = cname+"="+cvalue+"; "+expires;
            }
            setCookie(username,password,7);

            // 无封装，创建cookie
            // document.cookie=`username=${$("#srsjh>input").val()};expires=Thu, 18 Dec 2022 12:00:00 GMT`;
            // document.cookie=`password=${$("#mmk").val()};expires=Thu, 18 Dec 2022 12:00:00 GMT`;
            // document.cookie=`username=${$("#srsjh>input").val()}`;
            // document.cookie=`password=${$("#mmk").val()}`;
            // console.log(document.cookie);
            window.location.href="./index.html?";
        }
    })
})
